package com.wuyou.sso.common.excption;

/**
 * Exception
 *
 * @Date 2025/4/11 16:12
 * @Author 无忧
 */
public class CustomException extends RuntimeException{
    private static final long serialVersionUID = 1825226802361294349L;
    protected Object code;
    protected transient Object context;

    public CustomException() {
    }

    public CustomException(String message) {
        this(0, message);
    }

//    public CustomException() {
//    }

    public CustomException(Integer code, String message) {
        super(message);
        this.code = code;
    }

    public CustomException(Throwable cause) {
        super(cause);
    }

    public CustomException(String message, Throwable cause) {
        super(message, cause);
    }

    public CustomException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) {
        super(message, cause, enableSuppression, writableStackTrace);
    }

    public Object getCode() {
        return this.code;
    }

    public CustomException setCode(Object code) {
        this.code = code;
        return this;
    }

    public Object getContext() {
        return this.context;
    }

    public CustomException setContext(Object context) {
        this.context = context;
        return this;
    }

    public static CustomException of(String msg) {
        return new CustomException(msg);
    }

    public static CustomException of(String msg, Object context) {
        CustomException exception = new CustomException(msg);
        exception.setContext(context);
        return exception;
    }
}
